package backend.attribute.manager;

import java.util.List;

import org.hibernate.Session;
import core.attribute.model.Attribute;
import core.attribute.model.AttributeSet;
import core.util.HibernateCoreUtil;

public class AttributeManager  extends HibernateCoreUtil
{
	public List<Attribute> getAttributeList()
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List <Attribute> attribute = session.createQuery("from Attribute").list();	
		session.getTransaction().commit();
		return attribute ;
	}
	public Attribute getAttributeByUuid(Long uuid)
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Attribute attribute =  (Attribute)session.get(Attribute.class, uuid);
		session.getTransaction().commit();
		return attribute ;
	}
	public AttributeSet getAttributeSetByAttribute(Attribute at)
	{
		AttributeSet as = null ;
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		//List<AttributeSet> asLst = session.createQuery("from AttributeSet").add(Restrictions).list();
		session.getTransaction().commit();
		return as ;
	}
	public void save(Attribute a)
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.saveOrUpdate(a);
		//session.refresh(a);
		session.getTransaction().commit();
	}
	public void remove(Attribute a)
	{
		Session session = HibernateCoreUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		session.delete(a);
		session.getTransaction().commit();
	}
}
